﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Register : System.Web.UI.Page
{
    string usql;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            Panel2.Visible = false;
            Panel3.Visible = false;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string UserName = TextBox1.Text.Trim();
        if (UserName == "")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请输入用户名！');", true);
        }
        else
        {
            usql = "select count(*) from wj_User where wj_User='" + UserName + "'";
            int i = int.Parse(Class1.SelOne(usql));
            if (i == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('对不起，您输入的用户名不存在！');", true);
            }
            else
            {
                Panel1.Visible = false;
                Panel2.Visible = true;

                DataTable dt = Class1.ExecSel("select * from wj_User where wj_User='" + UserName + "'");
                txtQuestions.Text = dt.Rows[0]["wj_Questions"].ToString().Trim();
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string UserName = TextBox1.Text.Trim();
        string Answer = txtAnswer.Text.Trim();
       

        DataTable dt1 = Class1.ExecSel("select * from wj_User where wj_User='" + UserName + "'");
        if (dt1.Rows[0]["wj_Answer"].ToString().Trim() != Answer)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('对不起，你输入的答案有误！');", true);
        }
        else
        {
            Panel1.Visible = false;
            Panel2.Visible = false;
            Panel3.Visible = true;
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        string UserName = TextBox1.Text.Trim();
        string UserPwd1 = TextBox2.Text.Trim();
        string UserPwd2 = TextBox3.Text.Trim();
        if (UserPwd1 == "")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请输入密码！');", true);
        }
        else if (UserPwd2 == "")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请再次输入密码！');", true);
        }
        else if (UserPwd1 != UserPwd2)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('对不起，两次密码不同！');", true);
        }
        else
        {
            Md5Pw md5 = new Md5Pw();//MD5加密
            string Pwd1 = md5.Md5(UserPwd1);

            usql = "update wj_User set wj_UserPwd='" + Pwd1 + "' where wj_User='" + UserName + "'";
            Class1.ExecSql(usql);
            Response.Write("<script>alert('密码修改成功，请重新登陆！');location.href('uPassport.aspx')</script>");
        }
    }
}
